﻿$(document).ready(function () {
    mainmenu();
    $(".slide-tieubieu .item").mouseenter(function () {
            $(this).find('div.main-name').show();
            $(this).find('div.main-name').animate({ 'top': '110px' }, 1000, 'easeOutBounce');
        }).mouseleave(function () {
            $(this).find('div.main-name').animate({ 'top': '220px' }, 1000, 'easeOutBounce');
    });

    $(".slide-doatgiai .item").mouseenter(function () {
        $(this).find('div.main-name').show();
        $(this).find('div.main-name').animate({ 'top': '110px' }, 1000, 'easeOutBounce');
    }).mouseleave(function () {
        $(this).find('div.main-name').animate({ 'top': '220px' }, 1000, 'easeOutBounce');
    });

    $(".duthi li div.item").mouseenter(function () {
        $(this).find('div.main-name').show();
        $(this).find('div.main-name').animate({ 'bottom': '60px' }, 1000, 'easeOutBounce');
    }).mouseleave(function () {
        $(this).find('div.main-name').animate({ 'bottom': '-60px' }, 1000, 'easeOutBounce');
    });

    $('.slideheader').cycle({
        timeout: 6000
    });

    $('.slideUp1').cycle({
        timeout: 6000
    });

    $('.slideUp2').cycle({
        timeout: 6000
    });

    $('.slide-tieubieu').cycle({
        timeout: 6000,
        pager: '.paggingtieubieu',
        activePagerClass: 'active',
        pagerAnchorBuilder: function (idx, slide) {
            return '<div class="normal"></div>';
        }
    });

    $('.slide-doatgiai').cycle({
        timeout: 6000,
        pager: '.paggingdoatgiai',
        activePagerClass: 'active',
        pagerAnchorBuilder: function (idx, slide) {
            return '<div class="normal"></div>';
        }
    });

    $('.pagingDoatGiai a').click(function () {
        $('.pagingDoatGiai a').removeClass('pageactive');
        $(this).addClass('pageactive');
        $.ajax({
            url: '/Ajax/Ajax_BoxDoatGiai.aspx',
            type: 'GET',
            data: { 'PageIndex': $(this).html() , 'PageType' : 1 },
            dataType: 'html',
            beforeSend: function () {},
            success: function (data, textStatus, xhr) {
                if (data != null) {
                    $('.containerDoatGiai').html(data);
                }
            },
            error: function (xhr, textStatus, errorThrown) {}
        });
    });

    $('.pagingMoiNhat a').click(function () {
        $('.pagingMoiNhat a').removeClass('pageactive');
        $(this).addClass('pageactive');
        $.ajax({
            url: '/Ajax/Ajax_BoxMoiNhat.aspx',
            type: 'GET',
            data: { 'PageIndex': $(this).html(), 'PageType': 1 },
            dataType: 'html',
            beforeSend: function () {},
            success: function (data, textStatus, xhr) {
                if (data != null) {
                    $('.containerMoiNhat').html(data);
                }
            },
            error: function (xhr, textStatus, errorThrown) {}
        });
    });
});



function mainmenu() {
    $(" #nav ul ").css({ display: "none" }); // Opera Fix
    $(" #nav li").hover(function () {
        $(this).find('ul:first').css({ visibility: "visible", display: "none" }).show(400);
    }, function () {
        $(this).find('ul:first').css({ visibility: "hidden" });
    });
}

function getFacebookCommentCount(url, callback) {
    $.getJSON(url , function (data) {
        if (url && url != '#' && url != '') {
            if (!data['error']) {
                // callback(data.data[0]['share_count'], data.data[0]['comment_count']);
                callback(data.data[0]['share_count'], data.data[0]['commentsbox_count']);
            }
        }
    });
}

function SearchKeyPress(event) {
    var textSearch = document.getElementById('txtSearch');
    var strSearch = textSearch.value;
    var url = "";
    var key;
    if (window.event) {
        key = window.event.keyCode;
        if (key == 13) {
            if (textSearch.value != "") {
                strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');
                if (strSearch == "") return false;
                else if (strSearch.indexOf("?") != -1) return false;
                strSearch = encodeURIComponent(strSearch);
                url = "/tim-kiem.htm?KeySearch=" + strSearch + "&PageIndex=1&PageType=5";
                document.location.href = url;
                event.keyCode = 0;
                return false;
            }
            else {
                alert("Bạn chưa nhập từ khóa tìm kiếm !");
                return false;
            }
        }
    }
    else {
        key = event.which;
        if (key == 13) {
            if (textSearch.value != "") {
                strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');
                if (strSearch == "") return false;
                else if (strSearch.indexOf("?") != -1) return false;
                strSearch = encodeURIComponent(strSearch);
                url = "/tim-kiem.htm?KeySearch=" + strSearch + "&PageIndex=1&PageType=5";
                window.location.href = url;
                return false;
            }
            else {
                alert("Bạn chưa nhập từ khóa tìm kiếm !");

                return false;
            }

        }
    }
}
function OnSearchClick() {
    var textSearch = document.getElementById('txtSearch');
    if (textSearch.value != "") {
        var strSearch = textSearch.value;
        strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');
        if (strSearch == "") return false;
        else if (strSearch.indexOf("?") != -1) return false;
        strSearch = encodeURIComponent(strSearch)
        url = "/tim-kiem.htm?KeySearch=" + strSearch + "&PageIndex=1";
        if (document.all) {
            window.location.href = url;
        }
        else {
            document.location.href = url;
        }
        return false;
    }
    else {
        alert("Bạn chưa nhập từ khóa tìm kiếm!");
        return false;
    }
}

function SearchXemBinhChonKeyPress(event) {
    var textSearch = document.getElementById('txtSearch');
    var strSearch = textSearch.value;
    var url = "";
    var key;
    if (window.event) {
        key = window.event.keyCode;
        if (key == 13) {
            if (textSearch.value != "") {
                strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');
                if (strSearch == "") return false;
                else if (strSearch.indexOf("?") != -1) return false;
                //strSearch = encodeURIComponent(strSearch);
                ajaxSearchXemBinhChon($('#hdAwardId').val(), strSearch, 1, 2);
                event.keyCode = 0;
                return false;
            }
            else {
                alert("Bạn chưa nhập từ khóa tìm kiếm !");
                return false;
            }
        }
    }
    else {
        key = event.which;
        if (key == 13) {
            if (textSearch.value != "") {
                strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');
                if (strSearch == "") return false;
                else if (strSearch.indexOf("?") != -1) return false;
                //strSearch = encodeURIComponent(strSearch);
                ajaxSearchXemBinhChon($('#hdAwardId').val(), strSearch, 1, 2);
                return false;
            }
            else {
                alert("Bạn chưa nhập từ khóa tìm kiếm !");

                return false;
            }

        }
    }
}
function OnSearchXemBinhChonClick() {
    var textSearch = document.getElementById('txtSearch');
    if (textSearch.value != "") {
        var strSearch = textSearch.value;
        strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');
        if (strSearch == "") return false;
        else if (strSearch.indexOf("?") != -1) return false;
        //strSearch = encodeURIComponent(strSearch)
        ajaxSearchXemBinhChon($('#hdAwardId').val(), strSearch, 1, 2);
        return false;
    }
    else {
        alert("Bạn chưa nhập từ khóa tìm kiếm!");
        return false;
    }
}

function SearchListKeyPress(event) {
    var textSearch = document.getElementById('txtListSearch');
    var strSearch = textSearch.value;
    var url = "";
    var key;
    if (window.event) {
        key = window.event.keyCode;
        if (key == 13) {
            if (textSearch.value != "") {
                strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');
                if (strSearch == "") return false;
                else if (strSearch.indexOf("?") != -1) return false;
                //strSearch = encodeURIComponent(strSearch);
                event.keyCode = 0;
                // ajax
                ajaxSearch($('#hdAwardId').val(), strSearch, 1,2);
                return false;
            }
            else {
                alert("Bạn chưa nhập từ khóa tìm kiếm !");
                return false;
            }
        }
    }
    else {
        key = event.which;
        if (key == 13) {
            if (textSearch.value != "") {
                strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');
                if (strSearch == "") return false;
                else if (strSearch.indexOf("?") != -1) return false;
                //strSearch = encodeURIComponent(strSearch);
                // ajax
                ajaxSearch($('#hdAwardId').val(), strSearch, 1,2);
                return false;
            }
            else {
                alert("Bạn chưa nhập từ khóa tìm kiếm !");
                return false;
            }

        }
    }
}
function OnListSearchClick() {
    var textSearch = document.getElementById('txtListSearch');
    if (textSearch.value != "") {
        var strSearch = textSearch.value;
        strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');
        if (strSearch == "") return false;
        else if (strSearch.indexOf("?") != -1) return false;
        //strSearch = encodeURIComponent(strSearch)
        //ajax
        ajaxSearch($('#hdAwardId').val(), strSearch,1);
        return false;
    }
    else {
        alert("Bạn chưa nhập từ khóa tìm kiếm!");
        return false;
    }
}

function ajaxSearch(awardId , strSearch, pageIndex,pageType) {
    $.ajax({
        url: '/Ajax/AjaxSearchList.aspx',
        type: 'GET',
        data: { 'AwardsID': awardId, 'KeySearch': strSearch, 'PageIndex': pageIndex, 'PageType': pageType },
        dataType: 'html',
        beforeSend: function () { },
        success: function (data, textStatus, xhr) {
            if (data != null) {
                $('.containerList').html(data);
            }
        },
        error: function (xhr, textStatus, errorThrown) { }
    });
}

function ajaxSearchXemBinhChon(vongthi, strSearch, pageIndex, pageType) {
    $.ajax({
        url: '/Ajax/AjaxSearchListXemBinhChon.aspx',
        type: 'GET',
        data: { 'AwardsID': vongthi, 'KeySearch': strSearch, 'PageIndex': pageIndex, 'PageType': pageType },
        dataType: 'html',
        beforeSend: function () { },
        success: function (data, textStatus, xhr) {
            if (data != null) {
                $('.containerList').html(data);
            }
        },
        error: function (xhr, textStatus, errorThrown) { }
    });
}

function InputFocus(textdefault, control) {
    text = control.value;
    if (text == textdefault) control.value = "";
}

function InputBlur(textdefault, control) {
    text = control.value;
    if (text == "") control.value = textdefault;
}